package dao;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

public abstract class GenericDAO  {
	public Session sessao = HibernateUtil.getSessionFactory().openSession();
	public Query query;
	public Transaction transacao;
	
	
	public Boolean saveEntity(Object t){		
		try {
			transacao = sessao.beginTransaction();
			sessao.merge(t);
			transacao.commit();
			return true;
		} catch (HibernateException e) {
			System.out.println("Erro-"+getClass().toString()+" Mesagem de Erro: "+e.toString());
			return false;
		}
	}
	
	
	public Boolean deletaEntity(Object t){
		try {
			transacao = sessao.beginTransaction();
			sessao.delete(t);
			transacao.commit();
			return true;
		} catch (HibernateException e) {
			System.out.println("Erro-"+getClass().toString()+" Mesagem de Erro: "+e.toString());
			return false;
		}
	}
	
	public GenericDAO() {
		// TODO Auto-generated constructor stub
	}

}
